package com.woniu.woniuproject.utils;

import com.woniu.woniuproject.service.ProductAccountService;
import com.woniu.woniuproject.service.moneyCountService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 功能描述:<br>
 * 〈〉
 * @author EDZ
 * @create 2020/11/17
 * @since 1.0.0
 *
 * debtYearRate  年利率
 * debtMoney  贷款金额
 * month  还款月份
 *
 *
 */
public class moneyUtil {
    @Autowired
    ProductAccountService productAccountService;
    @Autowired
    moneyCountService moneyCountService;

    public  double changeMoney(double debtYearRate,double debtMoney,int month){
        //我们可以赚取的利息
        double moeny=debtMoney*0.01;
        //每月本金
        double reallymoney= debtMoney;
        for(int i=1;i<=month;i++){
            moeny+=(debtYearRate/12)*reallymoney;
            reallymoney=reallymoney-debtMoney/month;
        }
        //5天流标内的公司支出（不考虑5天内有人购买官标产品）
        Map map = productAccountService.queryall();
        List<Integer> list = (List<Integer>) map.get("list");
        List<Double> moneylist = (List<Double>) map.get("money");
        double count=0;//支出金额
        count+=0.095/30*5*moneylist.get(0);
        count+=0.080/90*5*moneylist.get(1);
        count+=0.075/120*5*moneylist.get(2);
        moeny-=count;
        if(moeny<0){//入不敷出
            return 0;
        }else {
            if(moeny<debtMoney*0.08){//投资回报率小于8%
                return 0;
            }else if(moeny<debtMoney*0.14){//投资回报率小于14%
                moneyCountService.inmoney(debtMoney*0.1);
                return debtMoney*0.1;
            }else{
                return debtMoney;
            }
        }
    }







}